//
//  LAB_Stick.m
//  Camera
//
//  Created by Bodi on 16/8/19.
//  Copyright © 2016年 葛海一. All rights reserved.
//

#import "LAB_Stick.h"
#import "LAB_GestureImageView.h"
#import "LAB_SaveViewController.h"
@implementation LAB_Stick

- (instancetype)initWithFrame:(CGRect)frame string:(NSString *)string{
    self = [super initWithFrame:frame];
    if (self) {
//        self.view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
//        [self addSubview:self.view];
//        self.gesView = [[LAB_GestureImageView alloc]initWithImage:[UIImage imageNamed:string] withFrame:CGRectMake(0, 0, 100, 100)];
//        self.view.center = self.gesView.center;
//        [self addSubview:self.gesView];
        
//        self.view = [[LAB_GestureImageView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
//        [self addSubview:self.view];
        self.gesView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:string]];
        self.gesView.frame = CGRectMake(10, 10, 90, 90);
//        self.gesView.center = self.view.center  ;
//        self.gesView.center = self.center;
        [self addSubview:self.gesView];
//        CGFloat x = self.view.frame.origin.x;
//        CGFloat y = self.view.frame.origin.y;
        
        self.button = [UIButton buttonWithType:UIButtonTypeCustom];
        _button.frame = CGRectMake(0 ,0 , 15, 15);
        //    _button.backgroundColor = [UIColor redColor];
        [_button setImage:[UIImage imageNamed:@"删除"] forState:UIControlStateNormal];
        //    [_button setBackgroundImage:[UIImage imageNamed:@"删除"] forState:UIControlStateNormal];
        [_button addTarget:self action:@selector(clear:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:_button];
        self.button.hidden = YES;

        
        
         [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(clears:) name:@"sss" object:nil];
        
        
    }
    return self;

}


- (void)clears:(NSNotification *)noti{
   
   self.button.hidden = NO;

    
}

- (void)setImageArr:(NSArray<UIImage *> *)imageArr{
    _imageArr = imageArr;
    _gesView = [[UIImageView alloc] initWithFrame:self.bounds];
    [self addSubview:_gesView];
    self.gesView.animationImages = imageArr;
    self.gesView.animationDuration = 0.15 * imageArr.count;
    self.gesView.animationRepeatCount = 0;
    [self.gesView startAnimating];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(clears:) name:@"sss" object:nil];
    
    self.button = [UIButton buttonWithType:UIButtonTypeCustom];
    _button.frame = CGRectMake(0 ,0 , 15, 15);
    //    _button.backgroundColor = [UIColor redColor];
    [_button setImage:[UIImage imageNamed:@"删除"] forState:UIControlStateNormal];
    //    [_button setBackgroundImage:[UIImage imageNamed:@"删除"] forState:UIControlStateNormal];
    [_button addTarget:self action:@selector(clear:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_button];
    self.button.hidden = YES;
}


- (void)clear:(UIButton *)button{
//    NSLog(@"asddasd");
    [self removeFromSuperview];
    
    
    
    
}

- (void)layoutSubviews{
//    self.view.backgroundColor = [UIColor whiteColor];
    self.backgroundColor = [UIColor clearColor];

}
@end
